package com.atguigu.order.Controller;

import com.atguigu.order.Properties.OrderProperties;
import com.atguigu.order.Service.OrderService;
import com.atguigu.order.bean.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderProperties orderProperties;

    @GetMapping("/config")
    public String getConfig() {
        return "超时时间：" + orderProperties.getTimeout() + "，确认信息：" + orderProperties.getAutoConfirm();
    }


    // 创建订单
    @GetMapping("/create")
    public Order createOrder(@RequestParam("userId") Long userId,
                             @RequestParam("productId") Long productId) {
        Order order = orderService.createOrder(userId, productId);
        return order;
    }
}
